import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'OTCOptionLifeCycleManagementM',
  state: {
    dictionary: {}, //所有字典枚举
  },
  effects: {
    // 获取期权结构枚举接口
    *getOptionStructData({ payload, callback }, { call, put }) {
      const response = payload['dictData'];
      console.log(response);
      if (response) {
        yield put({
          type: 'save',
          payload: {
            dictionary: response,
          },
        });
        callback('success', response);
      } else {
        callback('fail');
        message.error((response && response.msg) || '获取期权结构下拉列表失败');
      }
    },

    // 获取期权表格信息
    *queryOptionLifeList({ payload, callback }, { call, put }) {
      const response = yield call(api.OTCOptionLifeCycleManagement.queryOptionLifeList, payload);

      if (response) {
        callback('success', response);
      } else {
        callback('fail');
        message.error((response && response.msg) || '获取期权结构下拉列表失败');
      }
    },

    // 执行事件
    *updateOptionStatus({ payload, callback }, { call, put }) {
      const response = yield call(api.OTCOptionLifeCycleManagement.updateOptionStatus, payload);

      if (response) {
        callback('success', response);
      } else {
        callback('fail');
        message.error((response && response.msg) || '事件执行失败');
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
